package com.drool.mediaplayer.Adapters;

import com.drool.mediaplayer.R;
import com.drool.mediaplayer.panels.TranslucentPanel;

import android.content.Context;
import android.database.Cursor;

import android.net.Uri;
import android.provider.MediaStore.Audio;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AlbumBrowserAdapter extends CursorAdapter{

	public AlbumBrowserAdapter(Context context, Cursor c) {
		super(context, c);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		// TODO Auto-generated method stub
		//Log.i("adapter", "Binding ID" + cursor.getString(0) );
		
		TextView albumTxt = (TextView)view.findViewById(R.id.text1);
		TextView artistTxt = (TextView)view.findViewById(R.id.text21);
		//TextView dummyTxt = (TextView)view.findViewById(R.id.text2);
		TranslucentPanel dummy = (TranslucentPanel)view.findViewById(R.id.transparent_control_panel);
		TextView yearTxt = (TextView)view.findViewById(R.id.text3);
		TextView numSongsTxt = (TextView)view.findViewById(R.id.text4);
		
		ImageView albumArt = (ImageView) view.findViewById(R.id.albumImage);
		
		dummy.setVisibility(View.INVISIBLE);
		
		
		albumTxt.setText(cursor.getString(cursor.getColumnIndex(Audio.Albums.ALBUM)));
		artistTxt.setText("Artist: " + cursor.getString(cursor.getColumnIndex(Audio.Albums.ARTIST)));
		if (cursor.getString(cursor.getColumnIndex(Audio.Albums.FIRST_YEAR)) != null){
			yearTxt.setText("Year: " + cursor.getString(cursor.getColumnIndex(Audio.Albums.FIRST_YEAR)));
		}
		else
			yearTxt.setText("Year: Unknown");
		
		numSongsTxt.setText("Songs: " + cursor.getString(cursor.getColumnIndex(Audio.Albums.NUMBER_OF_SONGS)));
		
		
		if (cursor.getString(cursor.getColumnIndex(Audio.Albums.ALBUM_ART)) != null	){
			albumArt.setImageURI(Uri.parse(cursor.getString(cursor.getColumnIndex(Audio.Albums.ALBUM_ART))));
		}
		else
			albumArt.setImageURI(null);
		
		
		
	}

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		LayoutInflater inflater = LayoutInflater.from(context);
		View v = inflater.inflate(R.layout.layadapter, parent, false);
		bindView(v, context, cursor);
		return v;
	}
	
}
